package com.itbaizhan;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TestDateFormat02 {
    public static void main(String[] args) throws ParseException {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//创建对象
        String str = "2021-12-16 09:32:22";//定义String
        Date shjian = format.parse(str);//将字符串转为时间
        System.out.println(shjian.getTime());
        System.out.println(shjian);

        DateFormat format1 = new SimpleDateFormat("yyyy年MM月dd日 hh时mm分ss秒");
        Date date1 = new Date(34434543222L);
        String str2 = format1.format(date1); //转为String
        System.out.println(str2);

        Date now = new Date();//创建时间对象
        DateFormat f2 = new SimpleDateFormat("今年第D天，第w周");
        String str3 = f2.format(now);//转为String
        System.out.println(str3);
    }
}
